<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>修改工作列表</title>
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <link rel="stylesheet" th:href="@{/bootstrap.min.css}">
    <script th:src="@{/jquery-3.3.1.slim.min.js}"></script>
    <script th:src="@{/popper.min.js}"></script>
    <script th:src="@{/bootstrap.min.js}"></script>
    <script th:src="@{/axios.min.js}"></script>
    <script th:src="@{/vue.js}"></script>
</head>
<body>
<nav class="navbar navbar-expand-lg navbar-light bg-light">
    <a class="navbar-brand" href="#">后台管理</a>
    <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent"
            aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
        <span class="navbar-toggler-icon"></span>
    </button>

    <div class="collapse navbar-collapse" id="navbarSupportedContent">
        <ul class="navbar-nav mr-auto">
            <li class="nav-item active">
                <a class="nav-link" th:href="@{/release-work/admin/work}">发布工作管理 <span class="sr-only">(current)</span></a>
            </li>
            <li class="nav-item">
                <a class="nav-link" th:href="@{/release-work/admin/ucenter}">用户管理</a>
            </li>
            <li class="nav-item dropdown">
                <a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown"
                   aria-haspopup="true" aria-expanded="false">
                    更多
                </a>
                <div class="dropdown-menu" aria-labelledby="navbarDropdown">
                    <a class="dropdown-item" href="#">小程序管理</a>
                    <a class="dropdown-item" href="#">L</a>
                    <div class="dropdown-divider"></div>
                    <a class="dropdown-item disabled" href="#">待扩展</a>
                </div>
            </li>
            <li class="nav-item">
                <a class="nav-link disabled" href="#">待扩展</a>
            </li>
        </ul>
        <form class="form-inline my-2 my-lg-0">
            <input class="form-control mr-sm-2" type="search" placeholder="搜索" aria-label="搜索">
            <button class="btn btn-outline-success my-2 my-sm-0" type="submit">搜索</button>
        </form>
    </div>
</nav>
<div class="container">
    <form method="post" id="form" th:action="@{/release-work/work}">
        <input type="hidden" name="_method" value="put"/>
        <input type="hidden" name="id" th:value="${#httpServletRequest.getAttribute('work').getId()}">
        <div class="form-group">
            <label for="title">标题：</label>
            <input type="text" class="form-control" name="title" id="title"
                   th:value="${#httpServletRequest.getAttribute('work').getTitle()}"
                   th:placeholder="${#httpServletRequest.getAttribute('work').getTitle()}">
        </div>
        <div class="form-group">
            <label for="name">联系人：</label>
            <input type="text" class="form-control" id="name" name="name"
                   th:value="${#httpServletRequest.getAttribute('work').getName()}"
                   th:placeholder="${#httpServletRequest.getAttribute('work').getName()}">
        </div>
        <div class="form-group">
            <label for="phone">手机号：</label>
            <input type="text" class="form-control" id="phone" name="phone"
                   th:value="${#httpServletRequest.getAttribute('work').getPhone()}"
                   th:placeholder="${#httpServletRequest.getAttribute('work').getPhone()}">
        </div>
        <div class="form-group">
            <label for="status">状态（0代表审核没有通过，1代表审核通过）：</label>
            <input type="text" class="form-control" id="status" name="status"
                   th:value="${#httpServletRequest.getAttribute('work').getStatus()}"
                   th:placeholder="${#httpServletRequest.getAttribute('work').getStatus()}">
        </div>
        <div class="form-group">
            <label for="status">类型（1代表每日招工，0代表每日找活）：</label>
            <input type="text" class="form-control" id="typeOfWork" name="typeOfWork"
                   th:value="${#httpServletRequest.getAttribute('work').getTypeOfWork()}"
                   th:placeholder="${#httpServletRequest.getAttribute('work').getTypeOfWork() == 0 ? '每日招工' : '每日找活'}">
        </div>
        <div class="form-group">
            <label for="claim">详情：</label>
            <input type="text" class="form-control" id="claim" name="claim"
                   th:value="${#httpServletRequest.getAttribute('work').getClaim()}"
                   th:placeholder="${#httpServletRequest.getAttribute('work').getClaim()}">
        </div>
    </form>
    <button @click="submit" class="btn btn-primary">修改</button>
</div>
<script>
    new Vue({
        el: ".container",
        data() {
            return {}
        },
        methods: {
            submit() {
                let form = {};
                $("#form").serializeArray().forEach(item => {
                    form[item.name] = item.value;
                })
                axios
                    .put(`https://we9.91gongju.cn:10000/release-work/work`, form)
                    .then(response => window.location.replace(`https://we9.91gongju.cn:10000/release-work/admin/work`));
            }
        }
    })
</script>
</body>
</html>
